/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.seagate.app.manager;

import com.seagate.util.db.OracleConnectionPool;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author 452530
 */
public class MailListManager {
  public List getMailList() {
        List maillist=new ArrayList();
        String sql = "SELECT MAIL FROM AMA_STDPART_MAIL ";
        Connection conn = null;
        Statement stmt = null;
        ResultSet rset = null;
        try {
            conn = OracleConnectionPool.getConnection();
            stmt = conn.createStatement();
            rset = stmt.executeQuery(sql);
            while (rset.next() == true) {
                maillist.add(rset.getString("MAIL"));  
            }

        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                rset.close();
                stmt.close();
                conn.close();
            } catch (SQLException ex) {
            }
        }

        return maillist;
    }
   public boolean deleteMail(String mail) {
        boolean result = false;
        String sql = "";
          sql = "delete AMA_STDPART_MAIL where MAIL = '" + mail + "' ";


        Connection conn = null;
        Statement stmt = null;

        try {
            conn = OracleConnectionPool.getConnection();
            stmt = conn.createStatement();

            stmt.executeUpdate(sql);
            result = true;

        } catch (SQLException e) {
            System.err.println("sql = " + sql);
            System.err.println("code = " + e.getLocalizedMessage());
            result = false;
        } finally {
            try {
                stmt.close();
                conn.close();
            } catch (SQLException ex) {
            }
        }

        return result;
    }
   public boolean addMail(String mail) {
        boolean result = false;
        String sql = "";
        sql = "insert into AMA_STDPART_MAIL (MAIL) "
                    + " values ('" + mail + "')";

        Connection conn = null;
        Statement stmt = null;

        try {
            conn = OracleConnectionPool.getConnection();
            stmt = conn.createStatement();

            stmt.executeUpdate(sql);
            result = true;

        } catch (SQLException e) {
            System.err.println("sql = " + sql);
            System.err.println("code = " + e.getLocalizedMessage());
            result = false;
        } finally {
            try {
                stmt.close();
                conn.close();
            } catch (SQLException ex) {
            }
        }

        return result;
    }
   public boolean checkMail(String mail) {

        String sql = "SELECT * FROM AMA_STDPART_MAIL WHERE MAIL='"+mail+"'";
        Connection conn = null;
        Statement stmt = null;
        ResultSet rset = null;
        try {
            conn = OracleConnectionPool.getConnection();
            stmt = conn.createStatement();
            rset = stmt.executeQuery(sql);
            while (rset.next() == true) {

                return true;




            }

        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                rset.close();
                stmt.close();
                conn.close();
            } catch (SQLException ex) {
            }
        }

        return false;
    }
}
